/*
 * Copyright (c) 2022 Diemit <598757652@qq.com>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include "gpio_types.h"
#include "gpio_if.h"
#include "cmsis_os2.h"
#include "hdf_log.h"
#include "ohos_run.h"

#define SYS_DELAY_TICKS 200
#define TASK_STACK_SIZE 4096
#define TASK_PRIO 25

#define LED_OFF 0
#define LED_ON  1

// 在hcs文件中对应具体的GPIO口
#define M5STICKC_PLUS_LED_PIN 2      // LED

osThreadId_t g_taskID = NULL;

static void led_test(void)
{

    GpioSetDir(M5STICKC_PLUS_LED_PIN, GPIO_DIR_OUT);  // LED 配置为输出

    while (1) {

        GpioWrite(M5STICKC_PLUS_LED_PIN, LED_ON);

        osDelay(SYS_DELAY_TICKS);

        GpioWrite(M5STICKC_PLUS_LED_PIN, LED_OFF);

        osDelay(SYS_DELAY_TICKS);
    }

}

static void led_task(void)
{
    HDF_LOGE("into led test!\n");
    osThreadAttr_t attr;
    attr.name = "led_test";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = TASK_STACK_SIZE;
    attr.priority = TASK_PRIO;
    g_taskID = osThreadNew((osThreadFunc_t)led_test, NULL, &attr);
    if (g_taskID == NULL) {
        HDF_LOGE("Falied to create Test LED thread!\n");
    }
}

OHOS_APP_RUN(led_task);
